var conn = require('./mysqlServer');

// 查询   一条信息
function onlySearch(req, res, next) {
    conn.query(req.sql, req.data, function (err, result) {
        if(err) {
            res.send(JSON.stringify({code:500, err:"服务器内部错误"}));
        }
        if(result.length > 0) {
            req.result = result[0];
        }else{
            req.result = null;
        }

        next();
    })
}

// 注册--插入数据
function registUser(req, res, next) {
    conn.query(req.sql, req.data, function (err, result) {
        if(err) {
            res.send(JSON.stringify({code:500, err:"服务器内部错误"}));
        }
        res.send(JSON.stringify({code:200, msg:"注册成功"}));
    })
}

module.exports = {onlySearch, registUser};
